<template>
  <div>
    <el-button @click="handlePuppeteer">连接 Puppeteer</el-button>
    <el-button @click="handleScreenshot">截图</el-button>
    <el-button @click="handleGetWebview">获取webview</el-button>
  </div>
</template>

<script setup>
const handlePuppeteer = async () => {
  try {
    const result = await window.khj.puppeteer.connect()
    if (result.success) {
      console.log('连接成功:', result.data)
    } else {
      console.error('连接失败:', result.error)
    }
  } catch (error) {
    console.error('操作失败:', error)
  }
}

const handleScreenshot = async () => {
  try {
    const result = await window.khj.puppeteer.screenshot()
    if (result.success) {
      console.log('截图保存在:', result.data)
    } else {
      console.error('截图失败:', result.error)
    }
  } catch (error) {
    console.error('操作失败:', error)
  }
}

const handleGetWebview = async () => {
  const {data: webviewTarget} = await window.khj.puppeteer.getWebview()
  const page = webviewTarget.page()
  page.goto('https://www.baidu.com')
}
</script> 